from devicetest.aw.OpenHarmony import CommonOH
from devicetest.core.test_case import TestCase, Step

from aw.common import common_setup, common_teardown
from aw.pom import Memorandum


class PreTest_RK3568_Tooling_Memorandum_1500(TestCase, Memorandum):
    # 预置条件：
    # 烧写目标版本后，正常进入桌面
    # 测试步骤：
    # 1、进入桌面，点击备忘录，新增笔记
    # 2、进入笔记点击删除标识和长按笔记点击删除按钮，确认删除（覆盖两个删除入口）
    # 3、进入最近删除，点击笔记，点击删除，确认删除
    # 预期结果：
    # 1、可正常新增笔记
    # 2、删除成功，最近删除中显示对应已删除的笔记
    # 3、笔记永久删除，最近删除中笔记数量相应减少

    def __init__(self, controllers):
        self.TAG = self.__class__.__name__
        TestCase.__init__(self, self.TAG, controllers)

    def setup(self):
        common_setup(self.Phone1)

    def process(self):
        Step('步骤1：进入桌面，点击备忘录，新增笔记')
        CommonOH.startAbility(self.Phone1, self.ability_name, self.bundle_name)
        CommonOH.wait(self.Phone1, 1)
        CommonOH.click(self.Phone1, **self.add_note)
        CommonOH.wait(self.Phone1, 0.5)
        Step('预期结果1：可正常新增笔记')
        CommonOH.checkIfTextExist(self.Phone1, '标题')
        CommonOH.click(self.Phone1, **self.content_area)
        CommonOH.wait(self.Phone1, 0.5)
        CommonOH.inputTextByType(self.Phone1, type='Web', content='abc')
        CommonOH.click(self.Phone1, **self.save_note)

        Step('步骤2：删除笔记')
        CommonOH.click(self.Phone1, **self.del_note)
        CommonOH.wait(self.Phone1, 0.5)
        CommonOH.touchByText(self.Phone1, '删除')
        CommonOH.wait(self.Phone1, 0.5)
        Step('预期结果2：删除成功')
        CommonOH.checkIfTextExist(self.Phone1, '标题', expect=False)

        Step('步骤3：新增笔记')
        CommonOH.click(self.Phone1, **self.add_note)
        CommonOH.wait(self.Phone1, 0.5)
        CommonOH.click(self.Phone1, **self.content_area)
        CommonOH.wait(self.Phone1, 0.5)
        CommonOH.inputTextByType(self.Phone1, type='Web', content='abc')
        CommonOH.click(self.Phone1, **self.save_note)
        CommonOH.click(self.Phone1, **self.back)
        CommonOH.touchByText(self.Phone1, '标题', mode='LONG')
        CommonOH.wait(self.Phone1, 1)
        CommonOH.click(self.Phone1, **self.delete_menu)
        CommonOH.wait(self.Phone1, 1)
        CommonOH.touchByText(self.Phone1, '删除', index=1)
        Step('预期结果3：删除成功')
        CommonOH.checkIfTextExist(self.Phone1, '标题', expect=False)

        Step('步骤4：进入最近删除，点击笔记，点击删除，确认删除')
        CommonOH.click(self.Phone1, **self.open_menu)
        CommonOH.wait(self.Phone1, 1)
        CommonOH.touchByText(self.Phone1, '最近删除')
        CommonOH.wait(self.Phone1, 1)
        CommonOH.click(self.Phone1, **self.close_menu)
        CommonOH.wait(self.Phone1, 1)
        CommonOH.touchByText(self.Phone1, '标题')
        CommonOH.wait(self.Phone1, 1)
        # 底部删除
        CommonOH.click(self.Phone1, **self.delete_in_note_from_dustbin)
        # 弹窗的删除
        CommonOH.touchByText(self.Phone1, '删除', index=1)
        CommonOH.wait(self.Phone1, 0.5)
        CommonOH.touchByText(self.Phone1, '标题', mode='LONG')
        CommonOH.wait(self.Phone1, 0.5)
        CommonOH.click(self.Phone1, **self.delete_in_dustbin_main_page)
        CommonOH.wait(self.Phone1, 0.5)
        CommonOH.touchByText(self.Phone1, '删除', index=1)
        Step('预期结果4：笔记永久删除，最近删除中笔记数量相应减少')
        CommonOH.checkIfTextExist(self.Phone1, '没有笔记')
        CommonOH.click(self.Phone1, **self.open_menu)
        CommonOH.wait(self.Phone1, 0.5)
        CommonOH.touchByText(self.Phone1, '全部笔记')
        CommonOH.wait(self.Phone1, 0.5)
        CommonOH.click(self.Phone1, **self.close_menu)
        CommonOH.wait(self.Phone1, 0.5)
        CommonOH.checkIfTextExist(self.Phone1, '标题', expect=False)

    def teardown(self):
        common_teardown(self.Phone1, self.bundle_name)
